﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;



namespace 学生成绩查询及选课系统
{
    public partial class login : System.Web.UI.Page
    {
      

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btn_login_Click(object sender, EventArgs e)
        {
            string userid = txt_id.Text;
            string pwd = txt_pwd.Text;
            string sql = "select * from dbo.users where userid=@userid and pwd=@pwd";
            SqlParameter[] arraysql = { new SqlParameter("@userid", userid), new SqlParameter("@pwd", pwd) };
            SqlDataReader sdr = DBAccess.GetReader(sql, arraysql);
            if (sdr.Read() == true)
            {
                Session["user"] = sdr["username"].ToString();
                if (sdr["auth"].ToString() == "1")
                {
                    Response.Redirect("admin/mainView.aspx");
                  
                }
                else if (sdr["auth"].ToString() == "2")
                {
                    Response.Redirect("teacher/teacherMainView.aspx");
                }
                else
                {
                    Response.Redirect("MainPage.aspx");

                }  
                
            }
            else
            {
               lbl_tishi.Text = "账号密码错误";
            }
        }
    }
}